﻿namespace System.ServiceModel.Syndication
{
    using System.IO;
    using System.Xml;
    using AppLibrary.Util;

    public class BinarySyndicationContent : SyndicationContent
    {
        private SyndicationItem container;
        private String type;
        private Byte[] data;

        public BinarySyndicationContent(SyndicationItem container, String type, Byte[] data)
        {
            this.container = container;
            this.type = type;
            this.data = data;
        }

        public BinarySyndicationContent(SyndicationItem container, String type, Stream data)
            : this(container, type, data.ReadToEnd())
        {
        }

        public SyndicationItem Container
        {
            get { return this.container; }
            set { this.container = value; }
        }

        public override String Type
        {
            get { return this.type; }
        }

        public Byte[] Data
        {
            get { return this.data; }
            set { this.data = value; }
        }

        public void SetType(String type)
        {
            this.type = type;
        }

        public override SyndicationContent Clone()
        {
            BinarySyndicationContent clone = new BinarySyndicationContent(this.Container, this.Type, this.Data);
            clone.Container = this.Container;
            return clone;
        }

        protected override void WriteContentsTo(XmlWriter writer)
        {
            writer.WriteBase64(this.data, 0, this.data.Length);
        }
    }
}
